/*
 * Camera1.h
 *
 *  Created on: 27/07/2013
 *      Author: gonzalo
 */

#ifndef CAMERA_H_
#define CAMERA_H_

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>

#include <GL/glew.h>
#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <cmath>

class Camera {
private:
	glm::vec3 loc;
	glm::vec3 up_vector;
	glm::vec3 eye_dir;


	float camPitch, camYaw;
	float movevel;
	float mousevel;
	bool mi, ismoved;

	// La camara maneja la matriz de vista y proyeccion
	glm::mat4 ViewMatrix;
	glm::mat4 ProjectionMatrix;

	bool calculated;
	glm::mat4 ViewProjectionMatrix;

	void lockCamera();
	void update_view_matrix();

public:
	Camera();
	Camera(glm::vec3 loc);
	Camera(glm::vec3 loc, float yaw, float pitch);
	Camera(glm::vec3 loc, float yaw, float pitch, float mv, float mov);
	virtual ~Camera();

	glm::vec3 getVector();
	glm::vec3 getLocation();
	float getPitch();
	float getYaw();
	float getMovevel();
	float getMousevel();
	bool isMouseIn();

	void set_position(glm::vec3 vec);
	void lookAt(float pitch, float yaw);
	void mouseIn(bool b);
	void setSpeed(float mv, float mov);

	void moveCamera(float dir);
	void moveCameraUp(float dir);

	void rotateCamera(float pitch, float yaw);

	void perspective_projection(float angle, float aRatio, float near, float far);
	void orthogonal_projection(float left, float right,float bottom,float top, float near, float far);

	void bind_camera_position(GLint program, const char * name);
	void bind_view_matrix(GLuint program, const char * name);
	void bind_projection_matrix(GLuint program, const char * name);
	void bind_view_projection_matrix(GLuint program, const char * name);

	bool isMoved();

	glm::mat4 & getViewMatrix();
	glm::mat4 & getProjectionMatrix();
	const glm::mat4 & getViewProjectionMatrix();
};

#endif /* CAMERA1_H_ */
